<?php
declare (strict_types = 1);

namespace app\command\user;

use app\logic\model\user\UserLogicModel;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;

class VipExpire extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('user_vip_expire')
            ->setDescription('the user_vip_expire command');
    }

    protected function execute(Input $input, Output $output)
    {
        // 指令输出
        $output->writeln('user_vip_expire');
        $this->logic();//逻辑方法

        $output->writeln("操作时间为: ".date("Y-m-d H:i:s"));
    }
    public function logic()
    {
       $userModel = new UserLogicModel();
       $vip_user = $userModel->where('vip_id','>',0)
           ->where('vip_end_time','<',date('Y-m-d H:i:s'))
           ->column('id');
        if(!empty($vip_user)){
            $userModel->whereIn('id',$vip_user)
                ->save([
                   'vip_id'=>0,
                   'vip_end_time'=>null,
                ]);
        }
    }
}
